Conditions | 5 |
Total Lines | 218 |
Code Lines | 185 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from "react"; |
||
164 | |||
165 | public render(): React.ReactElement { |
||
166 | const { |
||
167 | application, |
||
168 | reviewStatusOptions, |
||
169 | isSaving, |
||
170 | intl, |
||
171 | portal, |
||
172 | } = this.props; |
||
173 | const l10nReviewStatusOptions = reviewStatusOptions.map((status) => ({ |
||
174 | value: status.value, |
||
175 | label: intl.formatMessage(messages[status.label]), |
||
176 | })); |
||
177 | const { selectedStatusId } = this.state; |
||
178 | const reviewStatus = |
||
179 | application.application_review && |
||
180 | application.application_review.review_status |
||
181 | ? application.application_review.review_status.name |
||
182 | : null; |
||
183 | const statusIconClass = className("fas", { |
||
184 | "fa-ban": reviewStatus === "screened_out", |
||
185 | "fa-question-circle": reviewStatus === "still_thinking", |
||
186 | "fa-check-circle": reviewStatus === "still_in", |
||
187 | "fa-exclamation-circle": reviewStatus === null, |
||
188 | }); |
||
189 | const applicantUrlMap: { [key in typeof portal]: string } = { |
||
190 | hr: routes.hrApplicantShow( |
||
191 | intl.locale, |
||
192 | application.applicant_id, |
||
193 | application.job_poster_id, |
||
194 | ), |
||
195 | manager: routes.managerApplicantShow( |
||
196 | intl.locale, |
||
197 | application.applicant_id, |
||
198 | application.job_poster_id, |
||
199 | ), |
||
200 | }; |
||
201 | const applicationUrlMap: { [key in typeof portal]: string } = { |
||
202 | hr: routes.hrApplicationShow( |
||
203 | intl.locale, |
||
204 | application.id, |
||
205 | application.job_poster_id, |
||
206 | ), |
||
207 | manager: routes.managerApplicationShow( |
||
208 | intl.locale, |
||
209 | application.id, |
||
210 | application.job_poster_id, |
||
211 | ), |
||
212 | }; |
||
213 | const jobUrlMap: { [key in typeof portal]: string } = { |
||
214 | hr: routes.hrJobPreview(intl.locale, application.job_poster_id), |
||
215 | manager: routes.managerJobPreview(intl.locale, application.job_poster_id), |
||
216 | }; |
||
217 | const jobApplicationsUrlMap: { [key in typeof portal]: string } = { |
||
218 | hr: routes.hrJobApplications(intl.locale, application.job_poster_id), |
||
219 | manager: routes.managerJobApplications( |
||
220 | intl.locale, |
||
221 | application.job_poster_id, |
||
222 | ), |
||
223 | }; |
||
224 | const applicantUrl = applicantUrlMap[portal]; |
||
225 | const applicationUrl = applicationUrlMap[portal]; |
||
226 | const jobUrl = jobUrlMap[portal]; |
||
227 | const jobApplicationsUrl = jobApplicationsUrlMap[portal]; |
||
228 | |||
229 | const getSaveButtonText = (): string => { |
||
230 | if (isSaving) { |
||
231 | return intl.formatMessage(messages.saving); |
||
232 | } |
||
233 | if (this.isUnchanged()) { |
||
234 | return intl.formatMessage(messages.saved); |
||
235 | } |
||
236 | return intl.formatMessage(messages.save); |
||
237 | }; |
||
238 | const saveButtonText = getSaveButtonText(); |
||
239 | const noteButtonText = |
||
240 | application.application_review && application.application_review.notes |
||
241 | ? intl.formatMessage(messages.editNote) |
||
242 | : intl.formatMessage(messages.addNote); |
||
243 | return ( |
||
244 | <div> |
||
245 | <div> |
||
246 | <div className="manager-application-preview-actions flex-grid"> |
||
247 | <div className="box small-1of3"> |
||
248 | <button |
||
249 | className="button--blue light-bg" |
||
250 | type="button" |
||
251 | onClick={() => this.handleLinkClicked(jobApplicationsUrl)} |
||
252 | > |
||
253 | {`< `} |
||
254 | <FormattedMessage |
||
255 | id="application.review.backToApplicantList" |
||
256 | defaultMessage="Save and Go Back to Applicant List" |
||
257 | description="Back Button text" |
||
258 | /> |
||
259 | </button> |
||
260 | </div> |
||
261 | <div className="box small-2of3"> |
||
262 | <a |
||
263 | className="button--blue light-bg" |
||
264 | href={jobUrl} |
||
265 | style={{ marginRight: ".5rem" }} |
||
266 | > |
||
267 | <FormattedMessage |
||
268 | id="application.review.button.viewJobPoster" |
||
269 | defaultMessage="View Job Poster" |
||
270 | description="View Job Poster Button text" |
||
271 | /> |
||
272 | </a> |
||
273 | <button |
||
274 | className="button--blue light-bg" |
||
275 | data-button-type="expand-all" |
||
276 | type="button" |
||
277 | id="expand-all" |
||
278 | > |
||
279 | <span className="expand"> |
||
280 | {" "} |
||
281 | <FormattedMessage |
||
282 | id="application.review.expandAllSkills" |
||
283 | defaultMessage="Expand All Skills" |
||
284 | description="Expand All Skills Button text" |
||
285 | /> |
||
286 | </span> |
||
287 | <span className="collapse"> |
||
288 | {" "} |
||
289 | <FormattedMessage |
||
290 | id="application.review.collapseAllSkills" |
||
291 | defaultMessage="Collapse All Skills" |
||
292 | description="Collapse All Skills Button text" |
||
293 | /> |
||
294 | </span> |
||
295 | </button> |
||
296 | </div> |
||
297 | </div> |
||
298 | </div> |
||
299 | |||
300 | <form className="applicant-summary"> |
||
301 | <div className="flex-grid middle gutter"> |
||
302 | <div className="box lg-1of11 applicant-status"> |
||
303 | <i className={statusIconClass} /> |
||
304 | </div> |
||
305 | |||
306 | <div className="box lg-2of11 applicant-information"> |
||
307 | <span className="name"> |
||
308 | {application.applicant.user.first_name}{" "} |
||
309 | {application.applicant.user.last_name} |
||
310 | </span> |
||
311 | <a |
||
312 | href={`mailto: ${application.applicant.user.email}`} |
||
313 | title={intl.formatMessage(messages.emailCandidate)} |
||
314 | > |
||
315 | {application.applicant.user.email} |
||
316 | </a> |
||
317 | {/* This span only shown for veterans */} |
||
318 | {(application.veteran_status.name === "current" || |
||
319 | application.veteran_status.name === "past") && ( |
||
320 | <span className="veteran-status"> |
||
321 | <img |
||
322 | alt={intl.formatMessage(messages.viewApplicationTitle)} |
||
323 | src={routes.imageUrl("icon_veteran.svg")} |
||
324 | />{" "} |
||
325 | {intl.formatMessage(messages.veteranStatus)} |
||
326 | </span> |
||
327 | )} |
||
328 | </div> |
||
329 | |||
330 | <div className="box lg-2of11 applicant-links"> |
||
331 | <a |
||
332 | title={intl.formatMessage(messages.viewApplicationTitle)} |
||
333 | href={applicationUrl} |
||
334 | > |
||
335 | <i className="fas fa-file-alt" /> |
||
336 | {intl.formatMessage(messages.viewApplicationText)} |
||
337 | </a> |
||
338 | <a |
||
339 | title={intl.formatMessage(messages.viewProfileTitle)} |
||
340 | href={applicantUrl} |
||
341 | > |
||
342 | <i className="fas fa-user" /> |
||
343 | {intl.formatMessage(messages.viewProfileText)} |
||
344 | </a> |
||
345 | </div> |
||
346 | |||
347 | <div className="box lg-2of11 applicant-decision" data-clone> |
||
348 | <Select |
||
349 | id={`review_status_${application.id}`} |
||
350 | name="review_status" |
||
351 | label={intl.formatMessage(messages.decision)} |
||
352 | required={false} |
||
353 | selected={selectedStatusId || null} |
||
354 | nullSelection={intl.formatMessage(messages.notReviewed)} |
||
355 | options={l10nReviewStatusOptions} |
||
356 | onChange={this.handleStatusChange} |
||
357 | /> |
||
358 | </div> |
||
359 | |||
360 | <div className="box lg-2of11 applicant-notes"> |
||
361 | <button |
||
362 | className="button--outline" |
||
363 | type="button" |
||
364 | onClick={this.showNotes} |
||
365 | > |
||
366 | {noteButtonText} |
||
367 | </button> |
||
368 | </div> |
||
369 | |||
370 | <div className="box lg-2of11 applicant-save-button"> |
||
371 | <button |
||
372 | className="button--blue light-bg" |
||
373 | type="button" |
||
374 | onClick={() => this.handleSaveClicked()} |
||
375 | > |
||
376 | <span>{saveButtonText}</span> |
||
377 | </button> |
||
378 | </div> |
||
379 | </div> |
||
380 | </form> |
||
381 | </div> |
||
382 | ); |
||
387 |